home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / pc / files / p_misc / tnc_pk80.arc / TNC2BAEA.MAC < prev   
Text File  |  1988-02-13  |  7KB  |  236 lines

  1. ; KISS-TNC-HEX-LOADER.MAC -  KISS TNC Intel Hex Loader v0.2
  2. ; k3mc 8 Aug 86 v0.1
  3. ;      4 Oct 86 v0.2
  4. ; v0.2 correctly sets the SP for either 16k or 32k of RAM, and strips
  5. ; the parity bit from incoming chars.
  6. ; v0.2 re-orged to fit in AEA 1.1.2 code (27128) by JPD 2/13/88
  7. ; Memory available: 0069-0080 (with msb set in first byte to truncate signon)
  8. ;            3F5E-3F80 (copyright msg)
  9. ;            3FA0-3FFF (unused)
  10.  
  11.     .z80
  12.     aseg
  13.     org    100h
  14.  
  15.  
  16. RAM    equ    8000h        ;Where the 16k x 8 (or 32k x 8) of RAM begins
  17.  
  18. ENQ    equ    5h
  19. ACK    equ    6h
  20. NAK    equ    15h
  21. colon    equ    ':'
  22.  
  23. rr_eof    equ    1        ;Record Type for End of File / begin execution
  24.  
  25.  
  26. ; SIO equates
  27.  
  28. SIO    equ    0dch        ;actually, only A5 is used for SIO -cs
  29.  
  30. A_dat    equ    SIO+0        ;Modem port
  31. A_ctl    equ    SIO+1        ;Modem port
  32.  
  33. B_dat    equ    SIO+2        ;user serial port
  34. B_ctl    equ    SIO+3        ;user serial port
  35.  
  36. RR0_RXR    equ    1        ;Receiver Char Avail bit
  37. RR0_TBE    equ    4        ;TX Buffer Empty bit
  38.  
  39.  
  40.  
  41. ;
  42. ; The general form of an Intel HEX record is as follows:
  43. ;
  44. ; :LLaaaaRRdddd..ddCC
  45. ;
  46. ; where LL is the number of bytes of data between RR and CC,
  47. ; not including RR or CC.
  48. ; aaaa is an address (see below),
  49. ; RR is a record type,
  50. ; dd are data bytes,
  51. ; and CC is a checksum, calculated as follows:
  52. ;   CC = - ( LL + aaaa + RR + dd + dd + ... ( modulo 256 ) )
  53. ; That is, adding all the bytes LL to CC (inclusive), you should get zero.
  54. ;
  55. ; These are the record types needed:
  56. ; RR = 00 record type = data. aaaa is the load address for the data.
  57. ; RR = 01 record type = end of file.
  58. ;  aaaa is the beginning execution address. LL is 00.
  59. ;  :00aaaa01CC
  60. ;  So, for example, if the start address is 8000, the last line of the file is
  61. ;  :008000017F
  62. ;
  63. ; In this implementation, trailing checksums are ignored; you don't even have
  64. ; to include them.
  65. ;-----------------------------------------------------------------------------
  66.     .phase    0069h        ;CHANGED FROM 4800H
  67.     defb   8DH    ;CR with MSB set => end of string
  68. start:
  69.     di            ;for this test, NO INTERRUPTS!
  70.  
  71. ; Figure out where top of stack is, set stack pointer.
  72. ; silly TNC-2 does not do complete address decoding for the RAMs if you are
  73. ; using only the two 8k x 8 chips.  Hack to figure out top of memory so we can
  74. ; set stack pointer.  This is REQUIRED by the KISS TNC.
  75.  
  76.     ld    a,55h        ;one value
  77.     ld    (0bfffh),a
  78.  
  79.     ld    a,0aah
  80.     ld    (0ffffh),a    ;other value
  81.  
  82.     ld    a,(0bfffh)    ;get what should be 55h if 32k
  83.  
  84.     cp    55h
  85.     ld    sp,0        ;assume for the moment it is
  86.     jr    z,stack_loaded    ;if so, then we've found TOS
  87.     ld    sp,0c000h    ;else all we've got is two 8k x 8 RAMs
  88. stack_loaded:
  89.  
  90. ;init SIO for async
  91.  
  92.     ld    b,nb        ;n bytes for init
  93.     ld    c,B_ctl        ;to B port
  94.     ld    hl,binit    ;with these bytes
  95.     otir            ;NOW!
  96.  
  97.     ld    a,5
  98.     out    (A_ctl),a    ;Ready WR5
  99.     ld    a,80h
  100.     out    (A_ctl),a    ;turn off STATUS LED
  101.  
  102. loop:
  103.     call    getchar        ;returns char into A reg
  104.     cp    ENQ        ;is it Control-E character?
  105.     jp    z,ENQCHR    ;yes, deal with it
  106.     cp    colon
  107.     jr    z,saw_colon    ;Go into Intel Hex download mode
  108.     and   5fh            ;UPPER CASE ONLY     ADDED BY WA7MXZ
  109.     cp    'H'            ; H for HOWIE of course
  110.     jp    z,00EDH        ;go get em' HOWIE
  111.     call    putchar        ;if neither, just echo it
  112.     jr    loop
  113.  
  114. saw_colon:
  115.     call    rdbyte
  116.     EX    AF,AF'        ;save in other register set for a sec
  117.     call    rdbyte
  118.     ld    h,a
  119.     call    rdbyte
  120.     ld    l,a
  121.     call    rdbyte
  122.     cp    rr_eof        ;is it record type 1 (begin execution)?
  123.     jr    nz,data_record    ;no, it's just another data record
  124. ;else we give machine to downloaded program
  125.     jp    (hl)        ;and go do it!
  126.  
  127. data_record:
  128.     EX    AF,AF'        ;get length value back
  129.     ld    b,a        ;and ready loop index
  130. load_loop:
  131.     call    rdbyte
  132.     ld    (hl),a
  133.     inc    hl
  134.     djnz    load_loop    ;load 'em up!
  135.  
  136. ; Note, we ignore checksums completely
  137.  
  138. find_colon:
  139.     call    getchar
  140.     cp    colon
  141.     jr    nz,find_colon    ;spin for a colon
  142.     jr    saw_colon    ;when we find colon, deal with next record
  143.  
  144. ;*** Reads 2 characters from SIO, converts them to binary, and returns value
  145. ;*** into A reg.  Disturbs no registers except AF.
  146. rdbyte:
  147.     push    bc
  148.     call    getchar
  149.     call    mk_binary
  150.     rlca
  151.     rlca
  152.     rlca
  153.     rlca
  154.     ld    b,a        ;save hi part
  155.     call    getchar
  156.     call    mk_binary
  157.      or    b        ;get hi + lo parts
  158.     pop    bc        ;be tidy
  159.     ret
  160.  
  161.  .dephase
  162.  .phase 3F5EH    ;>>>>>>>>>>>>>>>>RE-ORG TO FIT<<<<<<<<<<<<<<<<<<<<<<<<
  163.  
  164. ENQCHR:
  165.     ld    hl,ENQ_string
  166. ENQ_loop:
  167.     ld    a,(hl)
  168.     or    a
  169.     jp    z,loop
  170.     call    putchar
  171.     inc    hl
  172.     jr    ENQ_loop
  173.  
  174. ;*** Convert the ASCII character into Binary character (src & dest is A reg)
  175. ;*** Set carry flag if illegal hex char.
  176. mk_binary:
  177.     call    makeUC        ;if anybody uses lower case, it's OK
  178.     sub    '0'        ;convert ASCII -> binary (sorta)
  179.     ret    c        ;char < '0' => error
  180.     add    a,('0'-'G')    ;char > 'F' ?
  181.     ret    c        ;yes, illegal
  182.     add    a,6        ;char = A-F ?
  183.     jp     p,mk_b    ;yes, jump
  184.     add    a,7        ;char = ':'-'@'?
  185.     ret    c        ;yes, illegal
  186. mk_b:
  187.     add    a,10
  188.     or     a        ;clear carry => OK hex
  189.     ret
  190.  
  191.  .dephase
  192.  .phase 3FA0H        ;>>>>>>>>>>>RE-ORG TO FIT<<<<<<<<<<<<<<<
  193.  
  194. ;*** If the character in A reg is lower case, this makes it upper case.
  195. makeUC:
  196.     cp    'a'
  197.     ret    c        ;if less than an 'a' we're done
  198.     cp    'z'+1
  199.     ret    nc        ;if > than 'z', not a letter, so we're done
  200.     and    5fh        ;else force to UPPER CASE
  201.     ret
  202.  
  203. ;*** Get a char from user TTY (Port B), no interrupt mode. Return it in A reg.
  204. getchar:
  205.     in    a,(B_ctl)
  206.     and    RR0_RXR
  207.     jr    z,getchar    ;wait for a character to be typed
  208.     in    a,(B_dat)
  209.     and    7fh        ;strip parity bit (Phil's suggestion)
  210.     ret
  211.  
  212.  
  213. ;*** Put a character to user TTY (Port B), no interrupts.  Char is in A reg.
  214. putchar:
  215.     push    af        ;we will need A
  216. ploop:
  217.     in    a,(B_ctl)
  218.     and    RR0_TBE
  219.     jr    z,ploop        ;Wait for Transmitter buffer to become empty
  220.  
  221.     pop    af
  222.     out    (B_dat),a
  223.     ret
  224.  
  225.  
  226.  
  227. binit:    defb    1ah,0,14h,44h,3,0c3h,5,0eeh,11h,0    ;magic SIO inits
  228. bi_end    equ    $
  229. nb    equ    bi_end-binit    ;Number of bytes in previous string
  230.  
  231. ENQ_string:
  232.     defb    "KISS/Raw TNC Intel Hex Loader v0.2 for AEA 1.1.2",13,10,0
  233.     END    START
  234.  
  235.  
  236.